﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace Cms.Web.CmsSystem
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = EntLib.Request.GetString("action");
            if (action == "logout")
                FormsAuthentication.SignOut();
        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string user = txtUser.Text;
            string pass = txtPass.Text;
            string code = txtCode.Text;
            BLL.UserInfo bll = new Cms.BLL.UserInfo();
            if (Session["login_randomcode"] != null && Session["login_randomcode"].ToString() == code.Trim())
            {
                Model.Sys_Userinfo model = bll.GetByUserName(user);
                if (model == null)
                    lbmsg.Text = "不存在该用户!";
                else
                {
                    string encriptpass = EntLib.Utiltiy.MD5Encrypt(pass);
                    if (String.IsNullOrEmpty(model.Password))
                        encriptpass = "";
                    if (String.IsNullOrEmpty(model.Password))
                        model.Password = "";
                    if (model.Password == encriptpass)
                    {
                        EntLib.FormsPrincipal<Model.Sys_Userinfo>.SignIn(user, model, 60);
                        EntLib.CookiesUtility.setCookie("apptheme", model.Theme, 1);
                        Response.Redirect("Default.aspx");
                    }
                    else
                    {
                        lbmsg.Text = "用户名和密码错误!";
                    }
                }
            }
            else
            {
                lbmsg.Text = "验证码不正确!";
            }
        }
    }

}
